var platform = 'pad'; //设备类型
var appId = '1';//应用ID
var recommend_appId = '2';
var DATABASE_NAME = 'promodel/'+appId+'/www/db/esales.sqlite'; //数据库名
// var DATABASE_NAME = 'esales.sqlite';
var recomendHistoryArray =[]; //缓存数组集合
var recommend = "";//选择投保人、被保人、建议书
// if(navigator.onLine){//检测当前设备是否有网 如果有网查询服务器

//根据QueryString参数名称获取值
function getQueryStringByName(name){
     var result = location.search.match(new RegExp("[\?\&]" + name+ "=([^\&]+)","i"));
     if(result == null || result.length < 1){
         return "";
     }
     return result[1];
}
//tab切换
function tabSwitch($scope){
	$scope.currentTab = '1';
    $scope.onClickTab = function (tab) {
        $scope.currentTab = tab.url;
    }
    $scope.isActiveTab = function(tabUrl) {
        return tabUrl == $scope.currentTab;
    }
}
//跳转去创建建议书的app
function jumpToOtherApp($scope){
	var key ={};
    key["recommend"] = '1';
    var array ={};
    array["id"] = $scope.SelectdCollection.ID,//客户编号
    array["name"] = $scope.SelectdCollection.REAL_NAME,//客户姓名
    array["birth"] = $scope.SelectdCollection.BIRTHDAY,//客户生日
    array["age"] = "",//客户年龄
    array["sex"] = $scope.SelectdCollection.SEX,//客户性别
    array["ocup_code"] = $scope.SelectdCollection.OCCUPATION_CODE,//职业代码
    array["ocup_name"] = "",//职业名称
    array["ocup_type"] = "",//职业类型
    array["part_code"] = $scope.SelectdCollection.PLURALITY_OCCUPATION_CODE,//兼职代码
    array["part_name"] = "",//兼职名称
    array["part_type"] = "" //兼职类型
    key["info"] = array;
	var url = "promodel/"+recommend_appId+"/www/index.html#/menu/customer?pctype="+platform+"&proid="+recommend_appId;
    var jsonKey ={
        "serviceType":"LOCAL",
        "URL": url,
        "key":key
    };
    pushToViewController(jsonKey, function (){
		console.log("创建建议书跳转成功！");
    },function (){
        console.log("创建建议书跳转失败！")
    });   
}
//客户对象
function customerBean(){
	this.REAL_NAME = "";
	this.HOME_CITY =""; //所在城市
	this.MOBILE ="";
	this.ID ="";
	this.IOCN=""; //头像URL
}
//用户列表
function MenuList($scope,$compile,$ionicPopup,$timeout){
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER"
	};
	// queryTableDataByConditions 条件查询
	queryAllTableData(json ,function(data){ //调用成功
		if(data.length > 0){ 
			successPopup.close();
			var listStr = "";
			for(var i = 0 ; i < data.length ; i++){ 
				if(data[i].HOME_CITY == null){
					data[i].HOME_CITY = '请填写地址';
				}else{
					data[i].HOME_CITY = data[i].HOME_CITY;
				}
				if(data[i].MOBILE == null){
					data[i].MOBILE = '请填写手机号';
				}else{
					data[i].MOBILE = data[i].MOBILE;
				}
				listStr += '<dl ng-click="clickMenu(\''+data[i].ID+'\',\''+i+'\')" ng-class="{checked:'+i+' == selectedRow}">'+
								'<a>' +
									'<dt><img src="img/pic.png"/></dt>' +
									'<dd>' +
										'<span>'+ data[i].REAL_NAME +'</span>' +
										'<span>'+ data[i].HOME_CITY +'</span>' +
										'<span>'+ data[i].MOBILE +'</span>' +
									'</dd>' +
								'</a>'+
							'</dl>';
			}
			var txt = $compile(listStr)($scope);
	        var el = document.getElementById('user_list');
	        angular.element(el).html('').append(txt);
		}else{
       		var alertPopup = $ionicPopup.alert({
			       template: '<div class="pop_up_box">没有数据!</div>'
			     });
			$timeout(function() {
			      alertPopup.close();
			   }, 3000);
			successPopup.close();
		}
	},function(){ //失败
		alert("数据查询失败！")
	}); 	
}
//客户详情
function QueryCustomerDetails($scope,ID){
	//基本信息
	essentialInformation($scope,ID);
	//家属信息
	familyInformation($scope,ID);
}
//插入数据库---客户信息
function InsertDatabase($scope,SelectdCollection,$state,$compile,$rootScope,$ionicPopup,$timeout){
	var mailing_address = SelectdCollection.MAILING_ADDRESS;
	var status = SelectdCollection.ID;
	if(SelectdCollection.ID == undefined){
		SelectdCollection.ID = plugs.getUUid();
	}
	if(mailing_address == '单位地址'){
		mailing_address = SelectdCollection.COMPANY_ADDRESS
	}else if(mailing_address == '家庭地址'){
		mailing_address = SelectdCollection.HOME_ADDRESS
	}
	var ManipulateJson = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER",
		"conditions":[{"ID": SelectdCollection.ID}],
		"data": [{
			"ID": SelectdCollection.ID, //客户ID
			"CODE": '111', //客户唯一标识
			"REAL_NAME": SelectdCollection.REAL_NAME,//姓名
			"SEX": SelectdCollection.SEX,//性别
			"BIRTHDAY": $('.birthoayDate').text(),//生日
			"AGE": $scope.c_age, //年龄
			"TYPE": SelectdCollection.TYPE,//客户类型
			"IDTYPE": SelectdCollection.IDTYPE,//证件类型
			"IDNO": SelectdCollection.IDNO,//证件号
			"ID_START_DATE": '',//证件有效起日
			"ID_END_DATE": $('.validityDate').text(),//证件有效止日
			"MARRI_STATUS": SelectdCollection.MARRI_STATUS,//婚姻状况
			"NATIVE_PLACE": SelectdCollection.NATIVE_PLACE,//国籍
			"NATIONALITY": SelectdCollection.NATIONALITY,//民族
			"SOURCE": SelectdCollection.SOURCE,//客户来源
			"EDUCATION": SelectdCollection.EDUCATION,//学历
			"HOBBY": SelectdCollection.HOBBY,//爱好
			"ANNIVERSARY": $('.specialDay').text(),//特殊纪念日
			"INCOME": SelectdCollection.INCOME,//收入
			"OTHER_INCOME_WAY": SelectdCollection.OTHER_INCOME_WAY,//其他收入来源
			"WORK_UNIT": SelectdCollection.WORK_UNIT,//工作单位
			"HEIGHT": SelectdCollection.HEIGHT,//身高
			"WEIGHT": SelectdCollection.WEIGHT,//体重
			"ACCOUNT_TENDENCY": SelectdCollection.ACCOUNT_TENDENCY,//账户倾向
			"HOME_PROVINCE": SelectdCollection.HOME_PROVINCE,//家庭地址（省）
			"HOME_CITY": SelectdCollection.HOME_CITY,//家庭地址（市）
			"HOME_COUNTY": SelectdCollection.HOME_COUNTY,//家庭地址（区）
			"HOME_ADDRESS": SelectdCollection.HOME_ADDRESS,//家庭详细地址
			"HOME_ZIP_CODE": SelectdCollection.HOME_ZIP_CODE,//家庭邮编
			"COMPANY_PROVINCE": SelectdCollection.COMPANY_PROVINCE,//单位地址（省）
			"COMPANY_CITY": SelectdCollection.COMPANY_CITY,//单位地址（市）
			"COMPANY_COUNTY": SelectdCollection.COMPANY_COUNTY,//单位地址（区）
			"COMPANY_ADDRESS": SelectdCollection.COMPANY_ADDRESS,//单位详细地址
			"COMPANY_ZIP_CODE": SelectdCollection.COMPANY_ZIP_CODE,//单位邮编
			"HOME_PHONE": SelectdCollection.HOME_PHONE,//家庭电话
			"COMPANY_PHONE": SelectdCollection.COMPANY_PHONE,//公司电话
			"MOBILE": SelectdCollection.MOBILE,//手机号码
			"MAILING_ADDRESS": SelectdCollection.MAILING_ADDRESS,//邮寄地址
			"REMARKS": SelectdCollection.REMARKS,//备注
			"RGT_PROVINCE": SelectdCollection.RGT_PROVINCE,//户籍省
			"RGT_CITY": SelectdCollection.RGT_CITY,//户籍市
			"HOUSEHOLD_COUNTY": SelectdCollection.HOUSEHOLD_COUNTY, //户籍区
			"HOUSEHOLD_ADRESS": SelectdCollection.HOUSEHOLD_ADRESS, //户籍详细地址
			"CREATE_TIME": '2014-01-01',//创建时间
			"UPDATE_TIME": '2014-11-13',//修改时间
			"EMAIL": '',//邮箱
			"STATE": '',//状态
			"AGENT_CODE": '',//业务员编号
			"QQ": '',//QQ号
			"MSN": '',//msn号
			"WEIBO_TYPE": '',//微博类型
			"WEIBO_NO": '',//微博账号
			"PLURALITY_OCCUPATION_CODE": '',//兼职职业类别
			"FLAG": '',//判断数据是否同步
			"IOCN": '',//客户图像
			"IS_FOREVER": '',//长期有效
			"INCOME_WAY": '',//收入来源
			"OCCUPATION_CODE": ''//职业代码
		}]
	};
	updateORInsertTableDataByConditions(ManipulateJson,function(str){
		if(1 == str[0]){	
			MenuList($scope,$compile,$ionicPopup,$timeout);
        	if(status != undefined){
	       		var alertPopup = $ionicPopup.alert({
				       template: '<div class="pop_up_box">客户修改成功！</div>'
				     });
				$timeout(function() {
				      alertPopup.close();
				}, 3000);
				$timeout(function() {
				      	$scope.Track_Matte = false;
						$state.go('menu.list.user_details',{'id':SelectdCollection.ID});
						SelectdCollection.ID = undefined;
				   }, 1000);
			}else{
				var alertPopup = $ionicPopup.alert({
				       template: '<div class="pop_up_box">新增客户成功！</div>'
				     });
				$timeout(function() {
				      	alertPopup.close();
				   }, 3000);
				$timeout(function() {
				      	$scope.Track_Matte = false;
						$state.go('menu.list.user_details',{'id':SelectdCollection.ID});
						SelectdCollection.ID = undefined;
				   }, 1000);
			}
		}else{
       		var alertPopup = $ionicPopup.alert({
			       template: '<div class="pop_up_box">编辑客户失败，请重新编辑！</div>'
			     });
			$timeout(function() {
			      alertPopup.close();
			   }, 3000);
		}
	},function(){
		alert("数据插入异常！");
	})
}

//插入数据库---家属信息
function CreateFamilyInformation($scope,$compile,SelectdCollection,userID,$ionicPopup,$timeout){
	var F_ID = plugs.getUUid();
	var RELATION = SelectdCollection.RELATION;
	if(SelectdCollection.F_SEX == "男"){
		SelectdCollection.F_SEX = 0;
	}else{
		SelectdCollection.F_SEX = 1;
	}
	var FamilyJson = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER",
		"conditions":[{"ID": ''}],
		"data": [{
			"ID": F_ID, //客户ID
			"CODE": '111', //客户唯一标识
			"REAL_NAME":SelectdCollection.FamiliesName,//姓名
			"SEX": SelectdCollection.F_SEX,//性别
			"BIRTHDAY":  $('.FamiliesDate p').text(),//生日
			"AGE": $('.FamiliesDate span').text(), //年龄
			"TYPE": '',//客户类型
			"IDTYPE": '',//证件类型
			"IDNO": '',//证件号
			"ID_START_DATE": '',//证件有效起日
			"ID_END_DATE": '',//证件有效止日
			"IS_FOREVER": '',//长期有效
			"MARRI_STATUS": '',//婚姻状况
			"NATIVE_PLACE": '',//国籍
			"RGT_PROVINCE": '',//户籍省
			"NATIONALITY": '',//民族
			"SOURCE": '',//客户来源
			"EDUCATION": '',//学历
			"HOBBY": '',//爱好
			"ANNIVERSARY": '',//特殊纪念日
			"INCOME": '',//收入
			"INCOME_WAY": '',//收入来源
			"OTHER_INCOME_WAY": '',//其他收入来源
			"OCCUPATION_CODE": '',//职业代码
			"WORK_UNIT": '',//工作单位
			"HEIGHT": '',//身高
			"WEIGHT": '',//体重
			"ACCOUNT_TENDENCY": '',//账户倾向
			"HOME_PROVINCE": '',//家庭地址（省）
			"HOME_CITY": '',//家庭地址（市）
			"HOME_COUNTY": '',//家庭地址（区）
			"HOME_ADDRESS": '',//家庭详细地址
			"HOME_ZIP_CODE": '',//家庭邮编
			"COMPANY_PROVINCE": '',//单位地址（省）
			"COMPANY_CITY": '',//单位地址（市）
			"COMPANY_COUNTY": '',//单位地址（区）
			"COMPANY_ADDRESS": '',//单位详细地址
			"COMPANY_ZIP_CODE": '',//单位邮编
			"HOME_PHONE": '',//家庭电话
			"COMPANY_PHONE": '',//公司电话
			"MOBILE": '',//手机号码
			"EMAIL": '',//邮箱
			"MAILING_ADDRESS": '',//邮寄地址
			"REMARKS": '',//备注
			"CREATE_TIME": '2014-01-01',//创建时间
			"UPDATE_TIME": '2014-11-13',//修改时间
			"STATE": '',//状态
			"AGENT_CODE": '',//业务员编号
			"RGT_CITY": '',//户籍市
			"QQ": '',//QQ号
			"MSN": '',//msn号
			"WEIBO_TYPE": '',//微博类型
			"WEIBO_NO": '',//微博账号
			"PLURALITY_OCCUPATION_CODE": '',//兼职职业类别
			"FLAG": '',//判断数据是否同步
			"HOUSEHOLD_COUNTY": '', //户籍区
			"HOUSEHOLD_ADRESS": '', //户籍详细地址
			"IOCN": ''//客户图像
		}]	
	};
	updateORInsertTableDataByConditions(FamilyJson,function(str){
		if(1 == str[0]){
			var relationJson = 
			{
				"databaseName": DATABASE_NAME,
				"tableName": "T_CUSTOMER_FAMILY",
				"conditions":[{"ID": F_ID}],
				"data": [{
					"ID": F_ID, //家庭信息ID
					"FIRST_CUSTOMER_ID": userID,//主客户id
					"SECOND_CUSTOMER_ID": F_ID,//从客户id
					"RELATION": RELATION,//关系
					"CREATE_TIME":'2014-11-17',//创建时间
					"UPDATE_TIME":'2014-11-17',//修改时间
					"FLAG":''//判断数据是否同步
				}]	
			};
			updateORInsertTableDataByConditions(relationJson,function(str){
				if(1 == str[0]){	
					//MenuList($scope,$compile,$ionicPopup,$timeout);
					var alertPopup = $ionicPopup.alert({
				       template: '<div class="pop_up_box">客户关联成功！</div>'
				     });
					$timeout(function() {
					      alertPopup.close();
					   }, 3000);

				}else{
					var alertPopup = $ionicPopup.alert({
				       template: '<div class="pop_up_box">客户家属添加失败，请重试！</div>'
				     });
					$timeout(function() {
					      alertPopup.close();
					   }, 3000);
				}
				
			},function(){
				alert("数据插入异常！");
			})
		}else{
			console.log("数据插入失败！");
		}
	},function(){
		alert("数据插入异常！");
	})
}
//删除我的客户
function DeleteForm($state,$compile,ID,$scope,$ionicPopup,$timeout){
    var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER",
		"conditions": [{
			"ID": ID
		}]
	};
	deleteTableData(json,function(str){
		if(1 == str[0]){	
			MenuList($scope,$compile,$ionicPopup,$timeout);
			$state.go('menu.list.user_details',{'id':''});
		}else{
			var alertPopup = $ionicPopup.alert({
		       template: '<div class="pop_up_box">客户删除失败！</div>'
		     });
			$timeout(function() {
				alertPopup.close();
			}, 3000);
		}
    },function(){
        alert("数据删除异常！");
    });
}
//基本信息的查询
function essentialInformation($scope,ID){
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER",
		"conditions": {
			"ID": ID
		}
	};
	queryTableDataByConditions(json ,function(data){ //调用成功
		plugs.setUserBirthday($scope,data[0]["IDNO"],"c_birthday","c_age","isEffective");
		plugs.formValueSet($scope,data[0]);
		$scope.SelectdCollection = data[0];
		
		if(data[0].REAL_NAME != ''){
			document.getElementById('name_input').readOnly = true;
		}
	},function(){ //失败
		alert("数据查询失败！")
	});
}
//家属信息的查询
function familyInformation($scope,ID){
	var FamilyJson = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER_FAMILY",
		"conditions": {
			"FIRST_CUSTOMER_ID": ID
		}
	};
	queryTableDataByConditions(FamilyJson,function(data){ //调用成功
		if(data.length > 0){
			$scope.F_info = false;
			$scope.RELATION = data[0].RELATION;
			var json = {
				"databaseName": DATABASE_NAME,
				"tableName": "T_CUSTOMER",
				"conditions": {
					"ID": data[0].ID
				}
			};
			queryTableDataByConditions(json ,function(F_data){ //调用成功
				$scope.F_REAL_NAME = F_data[0].REAL_NAME;
				$scope.F_SEX = F_data[0].SEX;
				$scope.F_BIRTHDAY = F_data[0].BIRTHDAY;
			},function(){ //失败
				alert("数据查询失败！");
			});
			
		}else{
			$scope.F_info = true;
			console.log("没有家属信息!")
		}
	},function(){ //失败
		alert("数据查询失败！")
	});
}

//表单验证
function formValidation($scope){
	$scope.inputVerification = function(exType,value,input_id){
 		var errorMsg = document.getElementById(input_id);
		plugs.valdateForm($scope,0,value,exType,errorMsg);
		if(exType == 1){
			//alert(value);
			plugs.setUserBirthday($scope,value,"BIRTHDAY","c_age","isEffective"); 
		}
	}
}

//提交验证
function submitVerification($scope,SelectdCollection,returnFalg){
	//alert("sssssssss"+document.getElementById("HOME_ZIP_CODE"));
	var value =
        [{
            "value": SelectdCollection.REAL_NAME,
            "exType": "0",
            "errorMsg": document.getElementById("name_input")
        },
        {
            "value": SelectdCollection.IDNO,
            "exType": "1",
            "errorMsg": document.getElementById("clear_identify")
        },
        {
            "value": SelectdCollection.HOME_ZIP_CODE,
            "exType": "2",
            "errorMsg": document.getElementById("HOME_ZIP_CODE")
        },
        {
            "value": SelectdCollection.COMPANY_ZIP_CODE,
            "exType": "2",
            "errorMsg": document.getElementById("COMPANY_ZIP_CODE")
        },
        {
            "value": SelectdCollection.HOME_PHONE,
            "exType": "4",
            "errorMsg": document.getElementById("HOME_PHONE")
        },
        {
            "value": SelectdCollection.COMPANY_PHONE,
            "exType": "4",
            "errorMsg": document.getElementById("COMPANY_PHONE")
        },
        {
            "value": SelectdCollection.MOBILE,
            "exType": "3",
            "errorMsg": document.getElementById("MOBILE")
        },
        {
            "value": SelectdCollection.INCOME,
            "exType": "8",
            "errorMsg": document.getElementById("accout_clear")
        },
        {
            "value": SelectdCollection.HEIGHT,
            "exType": "8",
            "errorMsg": document.getElementById("clear_height")
        },
        {
            "value": SelectdCollection.WEIGHT,
            "exType": "8",
            "errorMsg": document.getElementById("weight_clear")
        }]; 
       // alert("2");
    returnFalg = plugs.valdateForm($scope,1,value);
    return returnFalg;
}

//清空客户表单
function EmptyForm($scope,SelectdCollection){
	var formArray =["SelectdCollection.REAL_NAME"];
	plugs.clearFormValSet($scope,formArray);
}

/************************************************************************************************************************/

//标签列表
function labelList(labelID,$scope,$compile){ 
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER_MARK"
//		"conditions": {"CUSTOMER_ID":"1"}
	};
	var labelStr = "";
	queryAllTableData(json,function(data){ //调用成功
		if(data.length > 0){  
			recomendHistoryArray  = data;   
			for(var i = 0 ; i < data.length ; i++){ 
				labelStr += '<div class="item item-button-right" ng-click="clickList(\''+data[i].ID+'\',\''+data[i].NAME+'\');" ng-class="{\"checked\":\''+data[i].ID+'\'== selectedRow}">'+
				'<div class="bottom">'+
			  	 data[i].NAME+
			    '<span class="number">33</span>'+
			  '</div>'+
			  '</div>';
				
			} 
		}
		var txt = $compile(labelStr)($scope);
        var el = document.getElementById(labelID);
        angular.element(el).html('').append(txt);
	},function(){ 
		console.log('查询本地客户标签出错！');
	});  
		
}

//添加标签
function addLabel($scope,$compile){ 
	var jsonStr ={
      "databaseName":DATABASE_NAME,
      "tableName": "T_CUSTOMER_MARK",
      "conditions": [{"ID": $scope.cMark.ID}],
      "data": [
              {
                "ID": $scope.cMark.ID,
                "NAME": $scope.cMark.NAME,
                "PARENTID":"0" , //默认准客户
                "STATE": '1',
                "CREATETIME":new Date(),
                "UPDATETIME":new Date(),
                "FLAG": "0",
                "CUSTOMER_ID":"12"
              }
          ]
      };
      updateORInsertTableDataByConditions (jsonStr,function(str){
        labelList("labellist",$scope,$compile);
        console.log("标签添加成功！");
      },function (){
        console.log("标签添加失败！");
      });
}
//删除标签
function removeLabel(ID,$scope,$compile){ 
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER_MARK",
		 "conditions": [{"ID": ID}]
	};
	deleteTableData(json ,function(str){ //调用成功
		labelList("labellist",$scope,$compile);
		console.log("标签删除成功！");
	},function(){ //失败
		alert("标签删除失败！")
	});  
		
}
// 修改标签
function changeLabel($scope,$compile) {
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER_MARK",
		"conditions": [{"ID": $scope.cMark.ID}],
		"data": [
              {
                "ID": $scope.cMark.ID,
                "NAME": $scope.cMark.NAME,
                "PARENTID":"0" , //默认准客户
                "STATE": '1',
                "CREATETIME":new Date(),
                "UPDATETIME":new Date(),
                "FLAG": "0",
                "CUSTOMER_ID":"12"
              }
          ]
	};
	updateORInsertTableDataByConditions (json,function(str){
        labelList("labellist",$scope,$compile);
        console.log("标签修改成功！");
      },function (){
        console.log("标签修改失败！");
      });
}
// 可添加的用户列表
function customerLabelList(customerID,$scope,$compile) {
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_CUSTOMER"
//		"conditions": {"CUSTOMER_ID":"1"}
	};
	var cusStr = "";
	queryAllTableData(json,function(data){ //调用成功
		if(data.length > 0){  
			recomendHistoryArray  = data;   
			for(var i = 0 ; i < data.length ; i++){ 
				cusStr += '<a class="item item-avatar client_check" ng-click="addlabel('+i+')">'+
		    				'<img src="img/pic.png">'+
		  					'<i class="circle"></i>'+
		    				'<p>'+data[i].REAL_NAME+'</p>'+
		    				'<p class="tel"><span>'+data[i].HOME_CITY+'</span>'+data[i].MOBILE+'</p>'+
							'</a>';
			} 
		}
		var txt = $compile(cusStr)($scope);
        var el = document.getElementById(customerID);
        angular.element(el).html('').append(txt);
	},function(){ 
		console.log('查询本地客户出错！');
	});  
}
//添加用户
function addLabelClient($scope,$compile){
	var json ={
      "databaseName":DATABASE_NAME,
      "tableName": "T_CUSTOMER_MARK_RELATION",
      "conditions": [{"CUSTOMER_ID": $scope.cMark.ID}]
      };
      updateORInsertTableDataByConditions (json,function(str){
        console.log("客户添加成功！");
      },function (){
        console.log("客户添加失败！");
      });
}

//职业代码查询
function queryList(tableID,$scope,$compile){ 
	var json = {
		"databaseName": DATABASE_NAME,
		"tableName": "T_OCCUPATION",
		"fuzzyConditions":'or',
		"conditions":
		{
			"OCCUPATION_CODE": $scope.OCCUPATION.WORD,
			"OCCUPATION_NAME": $scope.OCCUPATION.WORD
		}
	};
	var queryStr = "";
	fuzzyQueryTableDataByConditions(json,function(data){ //调用成功
		if(data.length > 0){  
			for(var i = 0 ; i < data.length ; i++){ 
				queryStr += '<div class="table_items row" code='+data[i].OCCUPATION_CODE+' code_name='+data[i].OCCUPATION_NAME+'>'+
				              '<div class="col">'+data[i].OCCUPATION_CODE+'</div>'+
				              '<div class="col">'+data[i].OCCUPATION_NAME+'</div>';
				              if(data[i].OCCUPATION_TYPE == -1 ){
				              	queryStr +='<div class="col">拒保</div>'+
				            '</div>';
				              }else{
				              	queryStr +='<div class="col">'+data[i].OCCUPATION_TYPE+'</div>'+
				            '</div>';
				              }				
			} 
		}
		var txt = $compile(queryStr)($scope);
        var el = document.getElementById(tableID);
        angular.element(el).html('').append(txt);
	},function(){ 
		console.log('查询出错！');
	});  
		
}

